"""
历史调度过度通用处理
"""

import pandas as pd
from io import BytesIO


class SheetResult:
    def __init__(self, sheet_name, rows):
        self.sheet_name = sheet_name
        self.rows = rows


class ExcelParser:

    def __call__(self, binary: BytesIO, start_row=0):
        """
            start_row：指定从哪一行开始读取数据，注意行索引从 0 开始
        """
        # 读取Excel
        xls = pd.ExcelFile(binary)
        res = []
        # 遍历所有工作表
        for sheet_name in xls.sheet_names:
            df = xls.parse(sheet_name=sheet_name, header=None, skiprows=start_row)

            rows = list(df.iterrows())
            if not rows and len(rows) < 1:
                continue
            res.append(SheetResult(sheet_name, rows))
        return res

    @staticmethod
    def row_number(binary: BytesIO):
        # 读取Excel
        xls = pd.ExcelFile(binary)
        total = 0
        # 遍历所有工作表
        for sheet_name in xls.sheet_names:
            df = xls.parse(sheet_name=sheet_name, header=None)
            total += len(list(df.iterrows()))
            return total
